package com.learn.sb.activemq.service.impl;

import com.learn.sb.activemq.pojo.User;
import com.learn.sb.activemq.service.ActiveMqService;
import org.apache.activemq.ActiveMQConnectionFactory;
import org.apache.activemq.jms.pool.PooledConnectionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.core.env.Environment;
import org.springframework.jms.annotation.JmsListener;
import org.springframework.jms.core.JmsTemplate;
import org.springframework.stereotype.Service;

import javax.jms.ConnectionFactory;
import java.util.ArrayList;
import java.util.List;

@Service
public class ActiveMqServiceImpl implements ActiveMqService {


    @Autowired
    private JmsTemplate jmsTemplate = null;
    // 自定义地址
    private static final String myDestination = "my-destination";

    @Override
    public void sendMsg(String message) {
        System.out.println("sendMsg: " + message);
        jmsTemplate.convertAndSend(message);
    }
    @Override
    @JmsListener(destination = "${spring.jms.template.default-destination}")
    public void receiveMsg(String message) {
        System.out.println("receiveMsg: " + message);
    }

    @Override
    public void sendUser(User user) {
        System.out.println("sendUser: " + user);
        jmsTemplate.convertAndSend(myDestination, user);
    }
    @Override
    @JmsListener(destination = myDestination)
    public void receiveUser(User user) {
        System.out.println("receiveUser: " + user);
    }


}
